package com.lagou.edu.utils;

import com.alibaba.druid.pool.DruidDataSource;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author 应癫
 */
public class DruidUtils {

    private DruidUtils(){
    }

    private static DruidDataSource druidDataSource = new DruidDataSource();
    private static final String DEFAULT_CONFIG="config.properties";


    static {
        Properties properties=new Properties();
        InputStream resourceAsStream = DruidUtils.class.getClassLoader().getResourceAsStream(DEFAULT_CONFIG);
        try {
            properties.load(resourceAsStream);
            druidDataSource.setDriverClassName(properties.getProperty("jdbcDriver","com.mysql.jdbc.Driver"));
            druidDataSource.setUrl(properties.getProperty("jdbcUrl","jdbc:mysql://localhost:3306/bank"));
            druidDataSource.setUsername(properties.getProperty("username","root"));
            druidDataSource.setPassword(properties.getProperty("password","root"));
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    public static DruidDataSource getInstance() {
        return druidDataSource;
    }

}
